<!DOCTYPE html>
<html lang="en" class="bg-white" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>合同管理</title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{../../assets/libs/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{../../assets/module/admin.css?v=311}"/>
</head>
<body>

<!-- 页面加载loading -->
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body layui-form layui-form-pane" lay-filter="test1">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">评论编号：</label>
                    <div class="layui-input-inline mr0">
                        <input id="product_id" class="layui-input" type="text" placeholder="输入评论编号"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <select id="product_type">

                    </select>
                </div>
                <div class="layui-inline">
                    <select id="sys_ct_status">
                        <option value="">评论类型</option>
                        <option value="0">商品评论</option>
                        <option value="1">需求评论</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
                    <button id="btnExp" class="layui-btn icon-btn"><i class="layui-icon">&#xe67d;</i>导出</button>
                </div>
            </div>
        </div>
    </div>
</div>
<table class="layui-table" id="logTable" lay-filter="logTable"></table>
</div>

<script type="text/html" id="barDemo">

</script>
<!-- js部分 -->
<script type="text/javascript" src="../../assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="../../assets/js/common.js?v=311"></script>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var laydate = layui.laydate;
        var arr=[
            {type: 'checkbox'},
            {field: 'commentId',align: 'center', title: '评论编号'},
            {field: 'userId',align: 'center', title: '评论者编号'},
            {align: 'center', title: '评论者头像',templet: function (item) {
                    return "<img  style='width: 20px;width: 20px;border-radius: 10px' src='"+item.avatarUrl+"' />";
                }
            },
            {field: 'nickName', align: 'center',title: '评论者昵称'},
            {field: 'commentFrom', align: 'center',title: '评论来源'},
            {align: 'center', title: '评论类别',templet: function (item) {
                    if (item.commentType==0) {
                        return "<button class='layui-btn layui-btn-xs layui-btn-warm'>商品评论</button>";
                    }
                    if (item.commentType==1) {
                        return "<button class='layui-btn layui-btn-xs layui-btn-normal'>需求评论</button>";
                    }
                }
            },
            {field: 'commentContent',align: 'center', title: '评论内容'},
            {field: 'gmtCreate',align: 'center', title: '发布时间'},
            {fixed: 'right', title:'操作',width:240,align: 'center',templet:function (item) {

                    return   ' <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="preview">查看</a>\n' +
                            ' <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>\n'+
                            ' <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>\n'
                }
            }
        ];
        getClassifty();
        getList();
        // 渲染表格
        // 搜索按钮点击事件
        $('#btnSearch').click(function () {
            var  sys_ct_status=0;
            var product_type=-1;
            if ($("#sys_ct_status").val()!=""){
                sys_ct_status=parseInt($("#sys_ct_status").val());
            }
            if ($("#product_type").val()!=""){
                product_type=parseInt($("#product_type").val());
            }
            var product_id="";
            if ($("#product_id").val()!=""){
                product_id=$("#product_id").val();
            }
            getListBy(product_id,product_type,sys_ct_status)
        });
        var insTb;
        function getClassifty() {
            $.ajax({
                type: "GET",
                url: "/product/getClassifty",
                headers:{
                    'token':"CF8EAA0839571E6F0D80D933F8FD6096709C5F8C690DD94F5144785F4E74A476"
                },
                dataType: "json",
                success: function (data) {
                    //console.log(data)
                    if (data.data.length>0){
                    //
                        $("#product_type").empty();
                        $("#product_type").append('<option value="">商品类别</option>')
                        var arr=data.data;
                        for (var i = 0; i < arr.length; i++) {
                            var item =arr[i]
                            $("#product_type").append('<option value="'+item.typeId+'">'+item.typeTitle+'</option>')
                        }
                        form.render(null, 'test1');
                    }
                }
            });
        }
        function  getList() {
            insTb=  table.render({
                elem: '#logTable',
                url: '/comment/getPageComment',
                page: true,
                cellMinWidth: 100,
                text: {
                    none: '暂无相关数据'
                },
                headers: {token: 'sasasas'},
                cols: [arr]
                ,response: {
                    statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
                }
                ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                    if (res.total>0){
                        return {
                            "code": 0, //解析接口状态
                            "msg": res.message, //解析提示文本
                            "count": res.total, //解析数据长度
                            "data": res.records //解析数据列表
                        };
                    }else {
                        return {
                            "code": 0, //解析接口状态
                            "msg": "暂无数据", //解析提示文本
                        };
                    }
                }
            });
        }
        function getListBy(product_id,product_type,sys_ct_status) {

            insTb=  table.render({
                elem: '#logTable',
                url: '/comment/getPageComment',
                page: true,
                cellMinWidth: 100,
                text: {
                    none: '暂无相关数据'
                },
                headers: {token: 'sasasas'},
                cols: [arr]
                ,response: {
                    statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
                },
                where: {
                    product_id:product_id,
                    product_type:product_type,
                    product_status: sys_ct_status
                }
                ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                    if (res.total>0){
                        return {
                            "code": 0, //解析接口状态
                            "msg": res.message, //解析提示文本
                            "count": res.total, //解析数据长度
                            "data": res.records //解析数据列表
                        };
                    }else {
                        return {
                            "code": 0, //解析接口状态
                            "msg": "暂无数据", //解析提示文本
                        };
                    }
                }
            });
           // product_type
        }
        table.on('tool(logTable)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'renewal') {
                layer.confirm('请确认合同是否续期？', {
                    btn: ['通过','取消'] //按钮
                }, function(){
                    $.ajax({
                        type: "POST",
                        url:"/sys/franchisee/updateStatus",
                        data:{
                            sys_cs_id:data.sys_cs_id,
                            sys_cs_status:1
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code==0){
                                layer.msg("续期成功！",{icon:1})
                                setTimeout(function () {
                                    layer.closeAll();
                                    window.location.reload();
                                },1000)
                            }
                        },
                    });
                });
            }
            if (layEvent === 'delete') {
                var  product_id=data.commentId;
                layer.confirm('请确认是否删除？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.ajax({
                        type: "DELETE",
                        url:"/comment/"+product_id,
                        dataType: "json",
                        headers: {
                            'token': "U2PGBjguSuJg"
                        },
                        success: function (data) {
                            if (data.status==200){
                                layer.msg(data.msg)
                                setTimeout(function () {
                                    layer.closeAll();
                                    window.location.reload();
                                },1000)
                            }
                        },
                    });
                }, function(){
                    layer.msg("已取消")
                });
            }
            if (layEvent === 'preview') { // 查看
                localStorage.setItem("product_id",data.productId);
                layer.open({
                    type: 2
                    ,title:"商品详情:"+data.productId
                    ,content:"product-priview"
                    ,area:['800px','500px']
                    ,shade: 0.3
                    ,maxmin:true
                    ,shadeClose:true
                    ,yes: function(){
                        layer.closeAll();
                    }
                });
            } else if (layEvent === 'edit') { // 删除
            }
            else if (layEvent === 'pass') { // 删除
                //  layer.msg('点击了修改');
                layer.confirm('请确认合同是否通过？', {
                    btn: ['通过','取消'] //按钮
                }, function(){
                    $.ajax({
                        type: "POST",
                        url:"/sys/franchisee/updateStatus",
                        data:{
                            sys_cs_id:data.sys_cs_id,
                            sys_cs_status:1
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code==0){
                                layer.msg("审核通过",{icon:1})
                                setTimeout(function () {
                                    layer.closeAll();
                                    window.location.reload();
                                },1000)
                            }
                        },
                    });
                }, function(){
                    layer.msg("已取消")
                });
            }
        });
        function clearImage(index){
            $.ajax({
                type: "POST",
                url: "/sys/contract/clearFranchisee",
                data: {
                    sys_ct_num:index
                },
                dataType: "json",
                success: function (data) {
                    if (data.code==0){
                        layer.msg("清除成功！",{icon:1})
                        setTimeout(function () {
                            layer.closeAll();
                            window.location.reload();
                        },1500)
                    }
                }
            });
        }
        //
        // 导出excel
        $('#btnExp').click(function () {
            var checkRows = table.checkStatus('logTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });
    });
</script>

</body>
</html>